package com.funny.mid;

import lombok.extern.slf4j.Slf4j;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Executable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * JDBC的内部封装
 *
 * @author fanxiao  2021/8/20
 * @since 1.0.0
 */
@Slf4j
public class DefaultSqlSession implements SqlSession{

	private Connection connection;

	private Map<String, XNode> mapperElement;


	public DefaultSqlSession(Connection connection, Map<String, XNode> mapperElement) {
		this.connection = connection;
		this.mapperElement = mapperElement;
	}

	@Override
	public <T> T selectOne(String statement) {
		try{
			PreparedStatement preparedStatement = connection.prepareStatement(statement);
			ResultSet resultSet = preparedStatement.executeQuery();
		}catch (Exception e){
			log.error(e.getMessage());
		}
		return null;
	}


	private <T> List<T> resultSet2Obj(ResultSet resultSet, Class<?> clazz) {
		List<T> list = new ArrayList<>();
		try{
			ResultSetMetaData metaData = resultSet.getMetaData();
			int columnCount = metaData.getColumnCount();
			while (resultSet.next()) {
				T t = (T) clazz.newInstance();
			}
		}catch(Exception e){
			log.error(e.getMessage());
		}
		return null;
	}
}
